package com.example.lck;


import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class Producer implements Runnable {
    private WareHouse wareHouse;
    private String name;

    public Producer(String name, WareHouse wareHouse) {
        this.wareHouse = wareHouse;
        this.name = name;
    }

    @Override
    public void run() {
        while (true) {
            Goods g = new Goods(UUID.randomUUID().toString(), new Random().nextInt());
            wareHouse.add(g);
            System.out.println(name + " producer add: " + g);
            try {
                TimeUnit.SECONDS.sleep(new Random().nextInt(5));
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}
